getDividends.wikifolio <- function (symbol, user="va", dbname="va_wikifolio", host="localhost", 
                                    datefrom="2000-01-01", dateto=NULL) {
  # connect to database
  con <- connectToVadb(user=user, dbname=dbname, host=host)
  
  sql <- sprintf("SELECT date,dividend 
                    FROM stockname LEFT JOIN dividends ON (id=stock_id) WHERE symbol='%s'", symbol)
  if (!is.null(datefrom)) {
    sql <- paste (sql, sprintf ("AND date>='%s'", datefrom))
  }
  if (!is.null(dateto)) {
    sql <- paste (sql, sprintf ("AND date<='%s'", dateto))
  }
  sql <- paste (sql,"ORDER BY `date`")
  
  div <- dbGetQuery(con, sql)
  if (nrow(div) > 0)  {
    div <- xts(div[,-1], as.Date(div$date, tz="UTC"))
    colnames(div) <- paste(symbol, "dividend", sep=".")
  } else {
    div <- NA
  }
  
  dbDisconnect(con)
  return (div)
}